import { Blog } from "../../blog/entities/blog.entity";
import { User } from "../../user/entities/user.entity";
import { utcToBeijing } from "../../utils";
import { Column, CreateDateColumn, Entity, ManyToOne, PrimaryGeneratedColumn } from "typeorm"

@Entity()
export class Star {
  @PrimaryGeneratedColumn()
  id: number

  @CreateDateColumn({
    type: 'timestamp',
    comment: '创建时间',
    transformer: {
      to(value: Date): number {
        return value ? value.getTime() : null;
      },
      from(value: number) {
        // 将UTC时间转换为北京时间
        return utcToBeijing(value)
      },
    },
  })
  createDate: Date

  @Column({
    comment: '稿件id'
  })
  createId: number

  @Column({
    comment: '稿件人id'
  })
  authorId: number

  @Column({
    comment:'收藏的用户id'
  })
  userId: number

  @Column({
    comment: '收藏业务类型',
    default: 0
  })
  type: number // 1博客文章 2说话 3评论 4图片

  @Column({
    comment: '文章id',
    nullable: true
  })
  blogId: number

  @Column({
    comment: 'ip',
    nullable: true
  })
  ip: string

  @ManyToOne(() => Blog, (blogInfo) => blogInfo.stars)
  blog: Blog[]

  @ManyToOne(()=>User, user=>user.stars)
  user: User
}
// 点赞数量保存在blog
// 点赞的人